home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / syntax / awk.vim < prev    next >
Encoding:
Text File  |  2001-09-02  |  7.3 KB  |  215 lines

  1. " Vim syntax file
  2. " Language:    awk, nawk, gawk, mawk
  3. " Maintainer:    Antonio Colombo <antonio.colombo@jrc.it>
  4. " Last Change:    2001 Sep 02
  5.  
  6. " AWK  ref.  is: Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
  7. " The AWK Programming Language, Addison-Wesley, 1988
  8.  
  9. " GAWK ref. is: Arnold D. Robbins
  10. " Effective AWK Programming, A User's Guide for GNU Awk
  11. " Edition 1.0.3, Free Software Foundation, 1997
  12.  
  13. " MAWK is a "new awk" meaning it implements AWK ref.
  14. " mawk conforms to the Posix 1003.2 (draft 11.3)
  15. " definition of the AWK language which contains a few features
  16. " not described in the AWK book, and mawk provides a small number of extensions.
  17.  
  18. " TODO:
  19. " Dig into the commented out syntax expressions below.
  20.  
  21. " For version 5.x: Clear all syntax items
  22. " For version 6.x: Quit when a syntax file was already loaded
  23. if version < 600
  24.   syn clear
  25. elseif exists("b:current_syntax")
  26.   finish
  27. endif
  28.  
  29. " A bunch of useful Awk keywords
  30. " AWK  ref. p. 188
  31. syn keyword awkStatement    break continue delete exit
  32. syn keyword awkStatement    function getline next
  33. syn keyword awkStatement    print printf return
  34. " GAWK ref. p. 268
  35. syn keyword awkStatement    nextfile
  36. " AWK  ref. p. 42, GAWK ref. p. 272
  37. syn keyword awkFunction    atan2 close cos exp int log rand sin sqrt srand
  38. syn keyword awkFunction    gsub index length match split sprintf sub
  39. syn keyword awkFunction    substr system
  40. " GAWK ref. p. 273-274
  41. syn keyword awkFunction    fflush gensub tolower toupper
  42. syn keyword awkFunction    systime strftime
  43.  
  44. syn keyword awkConditional    if else
  45. syn keyword awkRepeat    while for
  46.  
  47. syn keyword awkTodo        contained TODO
  48.  
  49. syn keyword awkPatterns    BEGIN END
  50. " AWK  ref. p. 36
  51. syn keyword awkVariables    ARGC ARGV FILENAME FNR FS NF NR
  52. syn keyword awkVariables    OFMT OFS ORS RLENGTH RS RSTART SUBSEP
  53. " GAWK ref. p. 260
  54. syn keyword awkVariables    ARGIND CONVFMT ENVIRON ERRNO
  55. syn keyword awkVariables    FIELDWIDTHS IGNORECASE RT RLENGTH
  56.  
  57. syn keyword awkRepeat    do
  58.  
  59. " Octal format character.
  60. syn match   awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
  61. syn keyword awkStatement    func nextfile
  62. " Hex   format character.
  63. syn match   awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
  64.  
  65. syn match   awkFieldVars    "\$\d\+"
  66.  
  67. "catch errors caused by wrong parenthesis
  68. syn region    awkParen    transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
  69. syn match    awkParenError    display ")"
  70. syn match    awkInParen    display contained "[{}]"
  71.  
  72. " 64 lines for complex &&'s, and ||'s in a big "if"
  73. syn sync ccomment awkParen maxlines=64
  74.  
  75. " Search strings & Regular Expressions therein.
  76. syn region  awkSearch    oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  77. syn region  awkBrackets    contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
  78. syn region  awkSearch    oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  79.  
  80. syn match   awkCharClass    contained "\[:[^:\]]*:\]"
  81. syn match   awkBrktRegExp    contained "\\.\|.\-[^]]"
  82. syn match   awkRegExp    contained "/\^"ms=s+1
  83. syn match   awkRegExp    contained "\$/"me=e-1
  84. syn match   awkRegExp    contained "[?.*{}|+]"
  85.  
  86. " String and Character constants
  87. " Highlight special characters (those which have a backslash) differently
  88. syn region  awkString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=awkSpecialCharacter,awkSpecialPrintf
  89. syn match   awkSpecialCharacter contained "\\."
  90.  
  91. " Some of these combinations may seem weird, but they work.
  92. syn match   awkSpecialPrintf    contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
  93.  
  94. " Numbers, allowing signs (both -, and +)
  95. " Integer number.
  96. syn match  awkNumber        display "[+-]\=\<\d\+\>"
  97. " Floating point number.
  98. syn match  awkFloat        display "[+-]\=\<\d\+\.\d+\>"
  99. " Floating point number, starting with a dot.
  100. syn match  awkFloat        display "[+-]\=\<.\d+\>"
  101. syn case ignore
  102. "floating point number, with dot, optional exponent
  103. syn match  awkFloat    display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
  104. "floating point number, starting with a dot, optional exponent
  105. syn match  awkFloat    display "\.\d\+\(e[-+]\=\d\+\)\=\>"
  106. "floating point number, without dot, with exponent
  107. syn match  awkFloat    display "\<\d\+e[-+]\=\d\+\>"
  108. syn case match
  109.  
  110. "syn match  awkIdentifier    "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
  111.  
  112. " Arithmetic operators: +, and - take care of ++, and --
  113. "syn match   awkOperator    "+\|-\|\*\|/\|%\|="
  114. "syn match   awkOperator    "+=\|-=\|\*=\|/=\|%="
  115. "syn match   awkOperator    "^\|^="
  116.  
  117. " Comparison expressions.
  118. "syn match   awkExpression    "==\|>=\|=>\|<=\|=<\|\!="
  119. "syn match   awkExpression    "\~\|\!\~"
  120. "syn match   awkExpression    "?\|:"
  121. "syn keyword awkExpression    in
  122.  
  123. " Boolean Logic (OR, AND, NOT)
  124. "syn match  awkBoolLogic    "||\|&&\|\!"
  125.  
  126. " This is overridden by less-than & greater-than.
  127. " Put this above those to override them.
  128. " Put this in a 'match "\<printf\=\>.*;\="' to make it not override
  129. " less/greater than (most of the time), but it won't work yet because
  130. " keywords allways have precedence over match & region.
  131. " File I/O: (print foo, bar > "filename") & for nawk (getline < "filename")
  132. "syn match  awkFileIO        contained ">"
  133. "syn match  awkFileIO        contained "<"
  134.  
  135. " Expression separators: ';' and ','
  136. syn match  awkSemicolon    ";"
  137. syn match  awkComma        ","
  138.  
  139. syn match  awkComment    "#.*" contains=awkTodo
  140.  
  141. syn match  awkLineSkip    "\\$"
  142.  
  143. " Highlight array element's (recursive arrays allowed).
  144. " Keeps nested array names' separate from normal array elements.
  145. " Keeps numbers separate from normal array elements (variables).
  146. syn match  awkArrayArray    contained "[^][, \t]\+\["me=e-1
  147. syn match  awkArrayElement      contained "[^][, \t]\+"
  148. syn region awkArray        transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
  149.  
  150. " 10 should be enough.
  151. " (for the few instances where it would be more than "oneline")
  152. syn sync ccomment awkArray maxlines=10
  153.  
  154. " define the default highlighting
  155. " For version 5.7 and earlier: only when not done already
  156. " For version 5.8 and later: only when an item doesn't have highlightling yet
  157. if version >= 508 || !exists("did_awk_syn_inits")
  158.   if version < 508
  159.     let did_awk_syn_inits = 1
  160.     command -nargs=+ HiLink hi link <args>
  161.   else
  162.     command -nargs=+ HiLink hi def link <args>
  163.   endif
  164.  
  165.   HiLink awkConditional        Conditional
  166.   HiLink awkFunction        Function
  167.   HiLink awkRepeat        Repeat
  168.   HiLink awkStatement        Statement
  169.  
  170.   HiLink awkString        String
  171.   HiLink awkSpecialPrintf    Special
  172.   HiLink awkSpecialCharacter    Special
  173.  
  174.   HiLink awkSearch        String
  175.   HiLink awkBrackets        awkRegExp
  176.   HiLink awkBrktRegExp        awkNestRegExp
  177.   HiLink awkCharClass        awkNestRegExp
  178.   HiLink awkNestRegExp        Keyword
  179.   HiLink awkRegExp        Special
  180.  
  181.   HiLink awkNumber        Number
  182.   HiLink awkFloat        Float
  183.  
  184.   HiLink awkFileIO        Special
  185.   "HiLink awkOperator        Special
  186.   "HiLink awkExpression        Special
  187.   HiLink awkBoolLogic        Special
  188.  
  189.   HiLink awkPatterns        Special
  190.   HiLink awkVariables        Special
  191.   HiLink awkFieldVars        Special
  192.  
  193.   HiLink awkLineSkip        Special
  194.   HiLink awkSemicolon        Special
  195.   HiLink awkComma        Special
  196.   "HiLink awkIdentifier        Identifier
  197.  
  198.   HiLink awkComment        Comment
  199.   HiLink awkTodo        Todo
  200.  
  201.   " Change this if you want nested array names to be highlighted.
  202.   HiLink awkArrayArray        awkArray
  203.   HiLink awkArrayElement    Special
  204.  
  205.   HiLink awkParenError        awkError
  206.   HiLink awkInParen        awkError
  207.   HiLink awkError        Error
  208.  
  209.   delcommand HiLink
  210. endif
  211.  
  212. let b:current_syntax = "awk"
  213.  
  214. " vim: ts=8
  215.